package day03

/**
  * 与类名相同并且用Object修饰的对象叫伴生对象
  * 类和其伴生对象之间可以互相访问私有的方法和属性
  */
class Dog {
  private var name = "二哈"
  def printName() : Unit ={
    println(Dog.CONSTANT + "," + name)
  }
}

object Dog{
  private val CONSTANT = "旺旺"

  def main(args: Array[String]): Unit = {
    val p = new Dog()
    //访问私有变量
    println(p.name)
    p.printName()
    //修改私有变量内容
    p.name = "大黄"
    p.printName()
  }
}